<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <canvas id="canvas" style="border: 1px solid #aaa; display: block; margin: 50px auto;">
        当前浏览器不支持Canvas，请更换浏览器
    </canvas>
    <script>
        window.onload = function () {
            var canvas = document.getElementById("canvas");

            canvas.width = 800;
            canvas.height = 800;

            var context = canvas.getContext("2d");

            context.fillStyle = '#058';
            context.font = 'bold 40px sans-serif';

            context.textBaseline = 'top';
            context.fillText('欢迎大家学习《Canvas绘图接口详解》！', 40, 100);
            drawBaseline(context, 100);

            context.textBaseline = 'middle';
            context.fillText('欢迎大家学习《Canvas绘图接口详解》！', 40, 200);
            drawBaseline(context, 200);

            context.textBaseline = 'bottom';
            context.fillText('欢迎大家学习《Canvas绘图接口详解》！', 40, 300);
            drawBaseline(context, 300);
        }

        function drawBaseline(cxt, h) {
            var width = cxt.canvas.width;
            cxt.save();
            cxt.strokeStyle = '#888';
            cxt.lineWidth = 2;
            cxt.moveTo(0, h);
            cxt.lineTo(width, h);
            cxt.stroke();
            cxt.restore();
        }
    </script>
</body>
</html>